using System;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
    /**
     * Classname : Nguoidung
     * Version information :1.0
     * Date  :26-09-2006
     * Copyright notice : 
     */

    public class DATruong : DbObject
    {
        protected SqlConnection connec;

        public DATruong(SqlConnection Connection)
        {
            connec = Connection;
        }
        // Kiem tra mat khau nguoi dung
        public DataSet LayDanhSachTruong()
        {
            // create the parameter
            DataSet dsTruong = RunProcedure("sp_Truong_loadLayDanhSachTruong", "TB_Truong", connec);
            for (int i = 0; i < dsTruong.Tables[0].Rows.Count; i++)
            {
                dsTruong.Tables[0].Rows[i]["Seq"] = (i + 1).ToString();
            }
            return dsTruong;
        }
		
		// return only the record with the specified ID!!!!!!!!!!!
        public DataRow loadTruongID(int TruongId)
		{
			// create the parameter
            SqlParameter[] parameters = { new SqlParameter("@TruongId", SqlDbType.Int, 4) };
            parameters[0].Value = TruongId;

            using (DataSet categorys = RunProcedure("sp_Truong_loadTruongID", parameters, "TB_Truong", connec))
			{
				return categorys.Tables[0].Rows[0];
			}
		}	

		// update the properties of the specified Categorys
		// Sua noi dung ban ghi hien hanh
        public int updateTruong(int TruongId, string TruongName)
		{
			int numAffected;
			// create the parameters
            SqlParameter[] parameters = { 	    new SqlParameter("@TruongId", SqlDbType.Int, 4),
											    new SqlParameter("@TruongName", SqlDbType.NVarChar, 128)
										};
			// set the values
            parameters[0].Value = TruongId;
            parameters[1].Value = TruongName.Trim();	
			// run the procedure
            RunProcedure("sp_Truong_updateTruong", parameters, out numAffected, connec);

			return numAffected;
		}

		// add a new question
		// Them ban ghi hien hanh
        public int insertTruong(string TruongName, int LanguageID)
		{
			int numAffected;
			// create the parameters
            SqlParameter[] parameters =  {	    new SqlParameter("@TruongName", SqlDbType.NVarChar, 128),
											    new SqlParameter("@TruongId", SqlDbType.Int ,4)
										 };	
			// set the values
            parameters[0].Value = TruongName.Trim();
			parameters[1].Direction = ParameterDirection.Output;
		
			// run the procedure
            RunProcedure("sp_Truong_insertTruong", parameters, out numAffected, connec);

			return (int)parameters[1].Value;
		}
		// Xoa Role
        public int removeTruong(int TruongID)
		{
			int numAffected;
			// create the parameters
            SqlParameter[] parameters = { new SqlParameter("@TruongID", SqlDbType.Int) };
            parameters[0].Value = TruongID;			
			// run the procedure
            try
            {
                RunProcedure("sp_Truong_removeTruong", parameters, out numAffected, connec);
            }
            catch
            {
                numAffected = 0;
            }
			return numAffected;			
		}
    }
}